package ru.dadle8;

import java.util.HashMap;
import java.util.Properties;

public abstract class AbstractProducer {

    protected Properties getProperties() {
        // create instance for properties to access producer configs
        Properties props = new Properties();
        props.putAll(new HashMap<>() {{
            //Assign localhost id
            put("bootstrap.servers", "localhost:29092");

            //Set acknowledgements for producer requests.
            put("acks", "all");

            //If the request fails, the producer can automatically retry,
            put("retries", 0);

            //Specify buffer size in config
            put("batch.size", 16384);

            //Reduce the no of requests less than 0
            put("linger.ms", 1);

            //The buffer.memory controls the total amount of memory available to the producer for buffering.
            put("buffer.memory", 33554432);

            put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
            put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        }});

        return props;
    }

    public abstract void sendMessages(String topicName);
}
